import { IPowerGrowRewardElement } from "../configs/PowerGrowReward"
import PowerGrowReward_Generate from "../ui-generate/PowerGrowReward_generate"

export class PowerGrowReward {
    uiWidget: UIWidget
    stage: boolean

    worldPosition: Vector
    targetUI: PowerGrowReward_Generate
    cfg:IPowerGrowRewardElement

    constructor() {
        this.uiWidget = <UIWidget>GameObject.spawn('UIWidget', { replicates: false })
        this.uiWidget.widgetSpace = WidgetSpaceMode.World
        this.uiWidget.occlusionEnable = false
        this.uiWidget.pivot = new Vector2(0.5, 1)
        this.targetUI = UIService.create(PowerGrowReward_Generate)
        this.uiWidget.setTargetUIWidget(this.targetUI.uiObject as UserWidget)
    }

    setInfo(position: Vector, cfg:IPowerGrowRewardElement) {
        this.worldPosition = position
        this.uiWidget.worldTransform.position = position
        this.cfg = cfg
        this.targetUI.img_icon.imageColor = LinearColor.colorHexToLinearColor(cfg.Color)
        this.targetUI.txt_value.text = `增加${cfg.GrowValue}力量`
        
    }

    onUpdate() {
        // 朝向摄像机
        let dir = Vector.multiply(Camera.currentCamera.worldTransform.getForwardVector(), -1)
        this.uiWidget.worldTransform.rotation = dir.toRotation()
        // 旋转动效
        this.targetUI.effect.renderTransformAngle = TimeUtil.elapsedTime() * 15
    }
}